<?php
if(!defined('DEDEINC')) exit("Request Error!");

require_once(LIB.'/datalistcp.class.php');
/**
 *问答模块控制器
 * by zsh
 */
class wenda extends Control {

    function wenda(){
        parent::__construct();
        $this->style = 'admin';
        // require_once(DEDEDATA.'/common.inc.php');
        // require_once (DEDEROOT . "/include/common.inc.php");
        $this->mwenda = $this->Model('mwenda');
    }

    function ac_index(){
        $search = request("search","");
        $sql = "select id,title,isTop,isGood,addTime,updateTime from `#@__guanjun_wenda` ";
        if($search == "search"){// 若是搜索调用则拼装search sql
            $keyword = request("keyword","") == "" ? "" : " where title like '%" . request("keyword","") . "%'";
            if($keyword != ""){
                $sql .= $keyword;
            }

            $order = request("order","");
            $attribution = request("attribution","");
            if( $order != "" && $attribution != ""){
                $orderby = " order by " . $attribution ." DESC, " . $order . " DESC";
                $sql .= $orderby;
            }else if($order != "" || $attribution != ""){
                 // $order = $order == "" ? "" : $order . " DESC";
                // $attribution = $attribution == "" ? "" : $attribution . " DESC";
                $orderby = " order by " . $order ." " . $attribution . "DESC";
                $sql .= $orderby;
            }

        }

        $dl = new DataListCP();
        $dl->pageSize = 10;              //设定每页显示记录数（默认25条）
        // $dl->style='admin';
        $dl->SetTemplate(DEDEROOT.'/wenda/templates/admin/index.htm');      //载入模板
        $dl->SetSource($sql);            //设定查询SQL
        $dl->Display();
    }

    function ac_wenda_add(){
        $doadd = request("doadd","");
        if($doadd != "doadd"){ // 添加记录界面
                $this->SetTemplate('wenda_add.htm');
                $this->Display();
        }else{ // 处理添加信息
            $title = request("title","");
            $isTop = request("isTop","");
            $isGood = request("isGood","");
            $content = request("content","");

            $addTime = $updateTime = date("Y-m-d H:i:s",time());
            $sql = "insert into #@__guanjun_wenda (title,content,isTop,isGood,addTime,updateTime)
            values ('$title','$content','$isTop','$isGood','$addTime','$updateTime') ";
            $this->mwenda->wenda_query($sql);
            ShowMsg("问答添加成功!","?wenda&ct=wenda");
        }

    }

    function ac_wenda_edit(){
        $doedit = request("doedit","");
        if($doedit != "doedit"){
            $id = intval(request("id",""));
            $where = "id = " . $id;
            $data = $this->mwenda->wenda_get_one($where);
            $this->SetVar("data",$data);
            $this->SetTemplate("wenda_edit.htm");
            $this->Display();
        }else{
            $title = request("title","");
            $isTop = intval(request("isTop",""));
            $isGood = intval(request("isGood",""));
            $content = request("content","");
            $id = intval(request("id",""));
            $updateTime = date("Y-m-d H:i:s",time());

            $sql = "update `#@__guanjun_wenda` set title='$title',isTop='$isTop',isGood='$isGood',content='$content',updateTime='$updateTime' where id=$id";

            $this->mwenda->wenda_query($sql);
            ShowMsg("问答修改成功!","?wenda&ct=wenda");
        }

    }

        function ac_wenda_delete(){
            $id = intval(request("id",""));
            $sql = "delete from `#@__guanjun_wenda` where id = $id";
            $this->mwenda->wenda_query($sql);
            ShowMsg("删除成功!","?wenda&ct=wenda");
        }

}

 ?>